import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:mtf/app/base/BaseController.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/utils/cache/AppCahche.dart';
import 'package:mtf/app/widget/VercodeTimerWidget.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class changePswController extends BaseController{
  var _isObscure=true.obs;
  set Obscure(value) => _isObscure.value = value;
  get Obscure => _isObscure.value;
  var _isTwoObscure=true.obs;
  set TwoObscure(value) => _isTwoObscure.value = value;
  get TwoObscure => _isTwoObscure.value;
  var user = AppCache.getUserInfo().obs;
  TextEditingController yzmController = TextEditingController();
  TextEditingController psw1Controller = TextEditingController();
  TextEditingController psw2Controller = TextEditingController();
  VercodeController verController = VercodeController();


  void reqChangePsw() async{
    var code=yzmController.text;
    var psw1=psw1Controller.text;
    var psw2=psw2Controller.text;
    if(code.isEmpty){
      SmartDialog.showToast("请输入验证码");
    }else if(psw1.isEmpty||psw2.isEmpty){
      SmartDialog.showToast("请输入修改的登录密码");
    }else if(psw1!=psw2){
      SmartDialog.showToast("请输入确认输入的登录密码是否一致");
    }else{
      showLoading();
      var resp=await HttpManager.reqUpdatePsw(psw1,psw2,code);
      if(resp.isSuccess()){
        SmartDialog.showNotify(msg: "修改成功", notifyType: NotifyType.success);
        Get.back();
      }
      hideLoading();

    }
  }

  void reqYzm() async{
    showLoading();
   var yzmReq= await HttpManager.reqYzm(user.value.phone ??"","new_up_password");
   if(yzmReq.isSuccess()){
     verController.vercodeSend();
   }
   hideLoading();
  }
}
